package com.gmail.blackdog1987.carcare.network.request.builder;

import android.content.Context;

import com.gmail.blackdog1987.carcare.Constant;
import com.gmail.blackdog1987.carcare.network.request.RequestBuilder;
import com.gmail.blackdog1987.carcare.util.DeviceUtils;
import com.gmail.blackdog1987.carcare.util.LogUtil;
import com.loopj.android.http.AsyncHttpClient;
import com.loopj.android.http.AsyncHttpResponseHandler;
import com.loopj.android.http.RequestParams;

public class CarChangeShopRequestBuilder extends RequestBuilder {

	private static final String TAG = CarChangeShopRequestBuilder.class.getSimpleName();
	private double lat;
	private double log;
	private int pageindex;
	private int pagesize;
	private int type;
	private String order;
	
	@Override
	public RequestParams buildRquest() {
		RequestParams params = new RequestParams();
		params.put("lat", String.valueOf(lat));
		params.put("log", String.valueOf(log));
		params.put("pageindex", String.valueOf(pageindex));
		params.put("pagesize", String.valueOf(pagesize));
		params.put("order", order);
		params.put("type", String.valueOf(type));
		return params;
	}
	
	public CarChangeShopRequestBuilder setLat(double lat){
		this.lat = lat;
		return this;
	}
	
	public CarChangeShopRequestBuilder setType(int type){
		this.type = type;
		return this;
	}
	
	public CarChangeShopRequestBuilder setOrder(String order){
		this.order = order;
		return this;
	}
	
	public CarChangeShopRequestBuilder setLon(double log){
		this.lat = log;
		return this;
	}
	public CarChangeShopRequestBuilder setPageSize(int pagesize){
		this.pagesize = pagesize;
		return this;
	}
	public CarChangeShopRequestBuilder setPageIndex(int pageindex){
		this.pageindex = pageindex;
		return this;
	}

	@Override
	public void postJsonRequest(Context context, AsyncHttpResponseHandler handler) {

		RequestParams params = buildRquest();
		
		AsyncHttpClient client = new AsyncHttpClient();
		client.setTimeout(Constant.TIMEOUT);
		client.setUserAgent(DeviceUtils.OS.getName());
		
		client.post(Constant.Action.CARCHANGESHOP, params, handler);
		LogUtil.d(TAG, "post : " + params);
	}

}
